<?php

require_once('lib/Schedule.php');
require_once('lib/Check.php');
require_once('lib/Util.php');
require_once('lib/MixiAppliAPI.php');

$api = new MixiAppliAPI(array_merge($_GET, $_POST));

$api->validate_params(array(
    'member_id'  => array(''),
    'start_date' => array('not_blank', 'date'),
    'end_date'   => array('not_blank', 'date'),
    'check'      => array('is_numeric'),
));

$member_id_ary = explode('-', $api->params['member_id']);
$member_id_ary = preg_grep('/^\d+$/', $member_id_ary);

$schedule_list = array();
foreach ($member_id_ary as $member_id) {
    $schedules = Schedule::get_list($member_id, $api->params['start_date'], $api->params['end_date']);
    if (!$schedules) continue;
    $schedule_list = array_merge($schedule_list, $schedules);
    if ($api->viewer_id != $member_id && isset($api->params['check']) && $api->params['check']) {
        $check = new Check();
        $check->member_id  = $member_id;
        $check->visitor_id = $api->viewer_id;
        $check->insert();
    }
}

$api->set_result($schedule_list);

?>
